<template>
  <div id="cesiumContainer"></div>
</template>

<script>
export default {
  data(){
    return{
      
    }
  },
  mounted(){
    var viewer = new Cesium.Viewer('cesiumContainer',{
       animation:false,       //是否显示动画控件
       homeButton:true,       //是否显示home键
       //geocoder:false,         //是否显示地名查找控件        如果设置为true，则无法查询
       baseLayerPicker:false, //是否显示图层选择控件
       timeline:false,        //是否显示时间线控件
       fullscreenButton:true, //是否全屏显示
       scene3DOnly:true,     //如果设置为true，则所有几何图形以3D模式绘制以节约GPU资源
       infoBox:true,         //是否显示点击要素之后显示的信息
       sceneModePicker:false,  //是否显示投影方式控件  三维/二维
       navigationInstructionsInitiallyVisible:false,
       navigationHelpButton:false,     //是否显示帮助信息控件
       selectionIndicator:false,        //是否显示指示器组件
       //加载谷歌卫星影像
       imageryProvider : new Cesium.UrlTemplateImageryProvider({url:"http://mt1.google.cn/vt/lyrs=s&hl=zh-CN&x={x}&y={y}&z={z}&s=Gali"}),
      //  imageryProvider : new Cesium.OpenStreetMapImageryProvider({url:"https://a.tile.openstreetmap.org/"}),
      //  terrainProvider : new Cesium.CesiumTerrainProvider({url: "https://www.supermapol.com/iserver/services/3D-stk_terrain/rest/realspace/datas/info/data/path/"})

      });
//       var osm = new Cesium.OpenStreetMapImageryProvider({
//     url : 'https://a.tile.openstreetmap.org/'
// });
      // var mapbox=new Cesium.MapboxImageryProvider({
      //         url:'https://api.mapbox.com/v4/',
      //         mapId: 'mapbox.dark',
      //         accessToken: 'pk.eyJ1Ijoic3g4NTQ5NjUxODUiLCJhIjoiY2toYnBjNG5hMGNoMzJ1bGZleTJmbXRmNyJ9.-QuDlX4hxOGVKX-xE37MDg',
      //     });
      //    viewer.imageryLayers.addImageryProvider(mapbox);
      // let woman = viewer.entities.add({
      //       id:'woman',
      //       position:Cesium.Cartesian3.fromDegrees(109.49404611080851,18.2966550140225,12.0),
      //       // 根据所提供的速度计算点
      //       // orientation: new Cesium.CallbackProperty(getOrientation, false),
      //       model: {
      //           uri: '/static/sy0.gltf',
      //           // runAnimations:new Cesium.CallbackProperty(getRun, false),
      //           // scale:0.012,
      //           // 贴地
      //           // heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
      //       },
      //   });
      var tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
            url: '/static/build3dtiles/tileset.json'
            // url: 'http://lab.earthsdk.com/model/908311a0ac2f11e99dbd8fd044883638/tileset.json'
            // url: 'http://data.marsgis.cn/3dtiles/qx-changfang/tileset.json'
        }));
        viewer.scene.primitives.add(tileset);
        tileset.readyPromise.then(function(tileset) {
          console.log(tileset)
            viewer.scene.primitives.add(tileset);
            var heightOffset = 0.0;  //高度
            // var lon =113.0;
            // var lat = 28.0;

            var boundingSphere = tileset.boundingSphere; 
            var cartographic = Cesium.Cartographic.fromCartesian(boundingSphere.center);
            // 2.0315174037137957, 0.6932788220496741,
            console.log(`${cartographic.longitude}, ${cartographic.latitude}, ${cartographic.height}`)
            // var offsetValue = Cesium.Cartographic.fromDegrees(lon,lat,heightOffset)
            
            debugger
            var surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, cartographic.height);
            // var surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.0);
            var offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, heightOffset);
            // var offset = Cesium.Cartesian3.fromRadians(offsetValue.longitude, offsetValue.latitude, heightOffset);
            var translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
            tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
            viewer.zoomTo(tileset, new Cesium.HeadingPitchRange(0.5, -0.2, tileset.boundingSphere.radius * 1.0));
        });
          }
    
    // var ss = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
    //             // url: 'http://data.marsgis.cn/3dtiles/jzw-shanghai/tileset.json',
    //             url: '/static/sss/tileset.json',
    //             // url: '/static/sss/scenetree.json',
    //             // url: '/static/sz.json'
    //             // url: 'https://iclient.supermap.io/examples/data/colorfulCityData.json'
    //             })).readyPromise.then(e=>{
    //                 var heightOffset = 10.0;
    //                 var boundingSphere = e.boundingSphere; 
    //                 var cartographic = Cesium.Cartographic.fromCartesian(boundingSphere.center);
    //                 var surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.0);
    //                 var offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, heightOffset);
    //                 var translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
    //                 e.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
    //                 viewer.zoomTo(e, new Cesium.HeadingPitchRange(0.5, -0.2, tileset.boundingSphere.radius * 1.0));
    //                 // viewer.flyTo(ss)
    //         }).otherwise(e=>{
    //           console.log(e)
    //           viewer.flyTo(ss)
    //         })
    //         viewer.flyTo(ss)
    }
  

</script>

<style>


</style>